<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class RmsBackendReferer
{
    /**
     * 验证是b.51kuafu.com 后台来的iframe请求，而非直接访问
     * @param Request $request
     * @param Closure $next
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if ($request->getHost() == 'tiger-api') {
            return $next($request);
        }
        $referer = (string)$request->header('Referer');
        if (Str::contains($referer, '51kuafu.com')) {
            return $next($request);
        }
        return redirect('https://www.kuafood.com/');
    }
}
